#!/usr/bin/perl
use strict;
=pod
FuzzySMSMatch (seedtoken, word)
1.	repetition are removed (call -> cal)
2.	missing vowels (waiting -> wtng, great->grt)
3.	only difference is in vowels (come -> cum, good->gud)
4.	characters replaced by digit (later -> l8er, great->gr8, forever->4evr )
5.	first and last character are similar
=cut

my $pattern = "[aeionu]";
my $digit = "[0-9]";

sub match(){
	my ($keyword, $var)= @_;
	my @key = split("",$keyword);
	my @vars = split("",$var);
	my $keyindex = 0;
	my $varindex = 0;

	while($keyindex <= $#key){
		if($key[$keyindex] eq $vars[$varindex]){$keyindex++; $varindex++;}
		elsif(($key[$keyindex] =~ /$pattern/) && ($vars[$varindex] =~ /$pattern/)){$keyindex++; $varindex++;}
		elsif($key[$keyindex] =~ /$pattern/){$keyindex++;}
		elsif(($varindex != 0)&&($key[$keyindex] eq $vars[$varindex-1])){$keyindex++;}
		elsif($vars[$varindex] =~ /$digit/){
			if($#vars < 2){return 0;}
			if(($varindex == $#vars)&&($#vars > 1)){return 1;}
			$varindex++;			
			while($key[$keyindex] ne $vars[$varindex]){
				$keyindex++;				
				if($keyindex == $#key+1){return 1;}
			}
		}
		else{ 
			if(($keyindex > 0.7*$#key)&&($#key > 3)){return 1;}
			else{return 0}
		}
	}
	return 1;
}		
 
my @matches =();
my @unmatch = (); 
my @arr = ('r', 'chrgs', 'charges', 'chargs', '2', 'cal', 'do', 'deactive', 'deact', 'airtel', 'activate', 'activ8' ,'artl', 'deactiv8', 'deactivate', 'dactiv8', 'deactivate', 'use', 'uz', 'S', 'is'); 
for(my $i=0; $i< $#arr+1; $i++){
	if(&match("deactive",$arr[$i])){ push @matches, $arr[$i]}
	else{push @unmatch, $arr[$i]}
}
print "match ::"."@matches"."\n";
print "unmatch ::"."@unmatch"."\n";
